package com.example.springboot.themeleafdemo.config;

import com.example.springboot.themeleafdemo.component.MyLocaleResolver;
import com.example.springboot.themeleafdemo.filter.MyFilter;
import com.example.springboot.themeleafdemo.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.Filter;
import javax.servlet.ServletRegistration;
import java.util.Arrays;

@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/").setViewName("index");
    }
    @Bean //向容器中添加组件
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver(); //返回值类型是之前国际化类的那个类
    }


//    //注册myservlet
//    @Bean
//    public ServletRegistrationBean myServlet(){
//        ServletRegistrationBean servletRegistration = new ServletRegistrationBean(new MyServlet(),"/myservlet");
//        return servletRegistration;
//    }
//
//    @Bean
//    public FilterRegistrationBean myFilter(){
//        FilterRegistrationBean<Filter> filterFilterRegistrationBean = new FilterRegistrationBean<>();
//        filterFilterRegistrationBean.setFilter(new MyFilter());
//        filterFilterRegistrationBean.setUrlPatterns(Arrays.asList("/hello","/myServlet"));
//        return filterFilterRegistrationBean;
//    }
}
